package sfeir.gwt.ergosum.server.guice;

import sfeir.gwt.ergosum.client.model.Person;
import sfeir.gwt.ergosum.server.service.ProfileService;
import sfeir.gwt.ergosum.server.service.ProfileServiceImpl;

import com.google.inject.Guice;
import com.google.inject.Injector;
import static com.google.inject.matcher.Matchers.*;

import com.google.inject.matcher.Matchers;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;

public class GuiceServletConfig extends GuiceServletContextListener {
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new ServletModule() {
            @Override
            protected void configure() {
                super.configure();
                // serve("/gwtergosum/client").with(ClientApiServiceImpl.class);
                // serve("/gwtergosum/import").with(ImportServlet.class);

                bind(ProfileService.class).to(ProfileServiceImpl.class);
                bindInterceptor(subclassesOf(ProfileService.class), returns(subclassesOf(Person.class).or(
                        subclassesOf(Long.class))), new LoggingInterceptor(), new CachingInterceptor());
            }
        });
    }
}
